package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.community.model.Organization;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 机构预收/预付款&结构结算
 * @author Liuyp
 *
 */
@Entity
@Table(name = "travel_organizationsettlement")
@Indexed
public class OrganizationSettlement extends BaseModel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6649230536218170538L;

	@Id
	@In
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkOrganizationSettlement;
	
	/**
	 * 款项类型
	 */
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private PaymentType paymentType;
	
	@JsonSerialize(using = EnumSerializer.class)
	public enum PaymentType {
		Advance("预收"),
		Prepaid("预付");
		private String display;
		PaymentType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	
	/** 款项内容 */
   	@Column
   	private String content;
	
   	/** 预计金额*/
	@Column
	private Double expectedAmount;
	
	/** 实际金额*/
	@Column
	private Double realAmount;
	
/*	*//** 付款单位*//*
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganizationr")
	@IndexedEmbedded
	private Organization payer;
	
	*//** 收款单位*//*
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganizatione")
	@IndexedEmbedded
	private Organization payee;*/
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOrganization")
	@IndexedEmbedded(depth = 1)
	private Organization orgInfo;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkAllianceOrg")
	@IndexedEmbedded(depth = 1)
	private AllianceOrg alliInfo;
	
	/** 预计（预收/预付）日期*/
	@Column
	@Field
	@Between
	private Date expectedDate;
	
	/** 结算日期*/
	@Column
	@Field
	@Between
	private Date realDate;
	
	/** 是否开票 */
   	@Column
   	private Boolean isInvoice;
   	
	/** 开票日期 */
   	@Column
   	@Field
   	@Between
   	private Date invoiceDate;
   	
   	/** 结算方式*/
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private PaymentMethod paymentMethod;
	
	@JsonSerialize(using = EnumSerializer.class)
	public enum PaymentMethod {
		Cash("现金"),
		WipeCard("刷卡"),
		Transfer("转账");
		private String display;

		PaymentMethod(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}
	
	/** 经办人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOperator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;
	
	/** 状态 */
   	@Enumerated(EnumType.STRING)
   	@In
   	@FieldBridge(impl = EnumBridge.class)
   	private Status status;
   	
   	@JsonSerialize(using = EnumSerializer.class)
   	public static enum Status {
   		Pending("待结算"),Settled("已结算");

   		private String display;
   		Status(String display) {
   			this.display = display;
   		}
   		public String getDisplay() {
   			return display;
   		}
   	}
   	
   	/** 备注 */
    @Column
	private String description;	
    
    @Version
	private Integer version;

	public Long getPkOrganizationSettlement() {
		return pkOrganizationSettlement;
	}

	public void setPkOrganizationSettlement(Long pkOrganizationSettlement) {
		this.pkOrganizationSettlement = pkOrganizationSettlement;
	}

	public PaymentType getPaymentType() {
		return paymentType;
	}

	public void setPaymentType(PaymentType paymentType) {
		this.paymentType = paymentType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Double getExpectedAmount() {
		return expectedAmount;
	}

	public void setExpectedAmount(Double expectedAmount) {
		this.expectedAmount = expectedAmount;
	}

	public Double getRealAmount() {
		return realAmount;
	}

	public void setRealAmount(Double realAmount) {
		this.realAmount = realAmount;
	}

	public Organization getOrgInfo() {
		return orgInfo;
	}

	public void setOrgInfo(Organization orgInfo) {
		this.orgInfo = orgInfo;
	}

	public AllianceOrg getAlliInfo() {
		return alliInfo;
	}

	public void setAlliInfo(AllianceOrg alliInfo) {
		this.alliInfo = alliInfo;
	}

	public Date getExpectedDate() {
		return expectedDate;
	}

	public void setExpectedDate(Date expectedDate) {
		this.expectedDate = expectedDate;
	}

	public Date getRealDate() {
		return realDate;
	}

	public void setRealDate(Date realDate) {
		this.realDate = realDate;
	}

	public Boolean getIsInvoice() {
		return isInvoice;
	}

	public void setIsInvoice(Boolean isInvoice) {
		this.isInvoice = isInvoice;
	}

	public Date getInvoiceDate() {
		return invoiceDate;
	}

	public void setInvoiceDate(Date invoiceDate) {
		this.invoiceDate = invoiceDate;
	}

	public PaymentMethod getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(PaymentMethod paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}
	
}
